#include <iostream>
#include <fstream>
#include <map>
#include <string>
using namespace std;
struct Record
{
	string _word;
	int _frequency;
};
class Dictionary{
public:
   bool is_word(const string & word){
       for(auto & letter : word){
        if(!isalpha(letter)){
            return false;
        }
       }
       return true;
   }
    void read(const char * filename){
        ifstream ifs(filename);
        string line;
        while(getline(ifs,line)){
            string word;
            while(ifs>>word){
                if(is_word(word)){
                    if(_dict.count(word)){
                        //如果_dict中有这个元素
                        ++_dict[word];
                    }else{
                        _dict.insert({word,1});
                    }
                }
            }
        }
    }
    void store(const char * filename){
        ofstream ofs(filename);
        auto it = _dict.begin();
        while(it != _dict.end()){
            ofs<<it->first<<" "<< it->second<<endl;
            ++it;
        }
        ofs.close();
    }
private:
    map<string,int> _dict;
};
void test(){
     Dictionary dc;
     dc.read("The_Holy_Bible.txt");
     dc.store("dict2.txt");
}
int main()
{
    test();
    return 0;
}

